/*
 * 作者：姚俊
 * 功能：按照日期查找action
 * 日期：2015-05-25
 */
package admin.action.fruits;

import java.util.List;

import admin.service.fruits.AwardService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Award;
import tools.StringDate;

public class AwardDateAction {
	
	private List<Award> awards;
	private String date1;
	private String date2;
	private int flag;
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;

	public List<Award> getAwards() {
		return awards;
	}

	public void setAwards(List<Award> awards) {
		this.awards = awards;
	}
	
	public String getDate1() {
		return date1;
	}

	public void setDate1(String date1) {
		this.date1 = date1;
	}

	public String getDate2() {
		return date2;
	}

	public void setDate2(String date2) {
		this.date2 = date2;
	}
	
	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public String execute()
	{
		int add=0;
		if(new AwardService().getCountAwardByDate(StringDate.StringToDate(this.getDate1()),
						StringDate.StringToDate(this.getDate2()))%Constant.pageSize!=0)
		{
			add=1;
		}
		ActionContext.getContext().put("flag", 1);
		this.setFlag(1);
		ActionContext.getContext().put("date11",this.getDate1());
		ActionContext.getContext().put("date22",this.getDate2());
		//最后一页
		this.setEndPage(new AwardService().getCountAwardByDate(StringDate.StringToDate(this.getDate1()),
						StringDate.StringToDate(this.getDate2()))/Constant.pageSize+add);
		this.setCounts(new AwardService().getCountAwardByDate(StringDate.StringToDate(this.getDate1()),
						StringDate.StringToDate(this.getDate2())));
		//通过日期查找所有的分页获奖
		awards=new AwardService().getSegregateAwardByDate(
				StringDate.StringToDate(this.getDate1()),
				StringDate.StringToDate(this.getDate2()),
				(this.getCurrentPage()-1)*Constant.pageSize+1,Constant.pageSize);

		return "succ";
	}


}
